package com.leetcode.partition2;

/**
 * @author `RKC`
 * @date 2021/10/20 9:15
 */
public class LC153寻找旋转排序数组中的最小值 {

    public static int findMin(int[] nums) {
        //通过二分查找找到最小值的索引
        int minIndex = -1, left = 0, right = nums.length - 1;
        while (left < right) {
            int mid = (left + right) >>> 1;
            if (nums[mid] > nums[right]) {
                left = mid + 1;
            } else if (nums[mid] < nums[right]) {
                right = mid;
            } else {
                right--;
            }
        }
        minIndex = left;
        return nums[minIndex];
    }

    public static void main(String[] args) {
        int[] nums = {3, 4, 5, 1, 2};
        System.out.println(findMin(nums));
    }
}
